//
//  HFUserAccountModel.swift
//  HFWeChat
//
//  Created by 黄来峰 on 16/4/20.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class HFUserAccountModel: NSObject,NSCoding{
    //"access_token":"2.00KpVf7GmMX7vDe52214f42criHTZE",
    //    "remind_in":"157679999",
    //    "expires_in":157679999,
    //    "uid":"5890875512"})
    var access_token: String?
    //一旦从服务器获取到准确的时间就立刻转化成日期
    var expires_in:NSTimeInterval = 0 {
        didSet{
            //计算过期日期
            expires_Date = NSDate(timeIntervalSinceNow: expires_in)
        }
        
    }
    var expires_Date:NSDate?
    var uid:String?
    var profile_image_url: String?
    var screen_name: String?
    //kvc 为属性赋值
    init(dict: [String: AnyObject]){
        super.init()
        setValuesForKeysWithDictionary(dict)
        
        
    }
    //空实现方法
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    //重新写
   override var description: String{
    let keys = ["access_token", "expires_Date" ,"uid","profile_image_url","screen_name"]
    return dictionaryWithValuesForKeys(keys).description
    
    }
    
    
    
    //归档
    func encodeWithCoder(aCode: NSCoder){
    
        aCode.encodeObject(access_token, forKey: "access_token")
        aCode.encodeObject(expires_Date, forKey: "expires_Date")
        aCode.encodeObject(uid, forKey: "uid")
        aCode.encodeObject(profile_image_url,forKey: "profile_image_url")
        aCode.encodeObject(screen_name, forKey: "screen_name")
   
    }
    
    
    
    //解档
    required init?(coder aDecoder: NSCoder) {
        
        access_token = aDecoder.decodeObjectForKey("access_token") as? String
        expires_Date = aDecoder.decodeObjectForKey("expires_Date") as? NSDate
        uid = aDecoder.decodeObjectForKey("uid") as? String
        profile_image_url = aDecoder.decodeObjectForKey("profile_image_url") as? String
        screen_name = aDecoder.decodeObjectForKey("screen_name") as? String
    }
    
    
}
